//
//  DoctorApplyViewController.m
//  QuickCure
//
//  Created by haoge on 16/9/10.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "DoctorApplyViewController.h"
#import "WYJApplyModel.h"
#import "WYJAppleTableViewCell.h"
#import "WYJDoctorDetailViewController.h"

@interface DoctorApplyViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation DoctorApplyViewController
// 模型数组的懒加载
- (NSMutableArray *)dataArray {
    
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
        for (int i = 0; i < 6; ++i) {
            WYJApplyModel *model = [[WYJApplyModel alloc] init];
//            model.name = @"张先生";
            model.name = [NSString stringWithFormat:@"张先生%d", i];
            model.disease = @"高血压";
            model.time = @"就诊于：2016/06/09";
            model.status = @"审核中";
            model.doctor = @"马医生";
            model.rank = @"主任医生";
            model.hospital = @"上海长征医院";
            model.location = @"上海长征医院2号楼心血管内科内科";
            model.pickTime = @"9:00 - 10:00";
            model.pickAddress = @"上海长征医院住院部";
            [_dataArray addObject:model];
        }
    }
    return _dataArray.copy;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 添加tableView
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [tableView registerClass:[WYJAppleTableViewCell class] forCellReuseIdentifier:@"applyCell"];
    tableView.rowHeight = 85;
    [self.view addSubview:tableView];
}
// 实现代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WYJAppleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"applyCell" forIndexPath:indexPath];
    WYJApplyModel *model = self.dataArray[indexPath.row];
    
    cell.model = model;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.btn_status.tag = indexPath.row;
    [cell.btn_status addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
    
    return cell;
}
// 指定点击cell后跳转的 预约医生信息详情 控制器
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [self moveToViewControllerWith:indexPath.row];
    
}

- (void)action:(id)sender {
    
    [self moveToViewControllerWith:[sender tag]];
    
}

- (void)moveToViewControllerWith:(NSInteger)modelIndex {
    WYJDoctorDetailViewController *doctorVC = [[WYJDoctorDetailViewController alloc] init];
    doctorVC.model = self.dataArray[modelIndex];
    doctorVC.title = @"预约医生信息详情";
    [self.navigationController pushViewController:doctorVC animated:YES];
    
}

@end
